package com.hopu.v1.service.admin.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopu.v1.mapper.admin.system.StaffSubjectMapper;
import com.hopu.v1.pojo.system.StaffSubject;
import com.hopu.v1.service.admin.system.StaffSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author DELL
* @description 针对表【s_staff_subject(员工学科关联表)】的数据库操作Service实现
* @createDate 2024-10-16 09:24:13
*/
@Service
public class StaffSubjectServiceImpl extends ServiceImpl<StaffSubjectMapper, StaffSubject>
    implements StaffSubjectService{
    @Autowired
    private StaffSubjectMapper staffSubjectMapper;

    @Override
    public void updateSubjectName(Integer empId, List<Integer> subjectIdList) {
        staffSubjectMapper.delete(new LambdaQueryWrapper<>(StaffSubject.class).eq(StaffSubject::getEmpId, empId));
        List<StaffSubject> subjects = subjectIdList.stream().map(subjectId -> {
            StaffSubject staffSubject = new StaffSubject();
            staffSubject.setEmpId(empId);
            staffSubject.setSubjectId(subjectId);
            return staffSubject;
        }).toList();
        saveBatch(subjects);
    }
}




